package dwz.web.listenerAndInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import dwz.business.lotto.DaiLiHuiyuanInterface;
import dwz.persistence.beans.DaiLiHuiyuan;
import dwz.web.management.lotto.CommonFields;

public class ModifyBackPasswordInterceptor implements HandlerInterceptor{
	@Autowired
	DaiLiHuiyuanInterface daiLiHuiyuanInterface;
	@Override
	public void afterCompletion(HttpServletRequest arg0,
			HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		
		
	}

	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
			Object arg2, ModelAndView arg3) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1,
			Object arg2) throws Exception {
		if(arg0.getSession().getAttribute(CommonFields.USERID)==null){ //如果session失效
			arg1.sendRedirect("/back");
			return false;
		}
		Integer isModifyPassword = (Integer) arg0.getSession().getAttribute(CommonFields.ISMODIFYPASSWORD);
		boolean isPass = false;
		
		
		if(isModifyPassword == 1){
			isPass = true;
		}else {
			
			
			String uri = arg0.getRequestURI();
			if(uri.contains("houtai/")&&!uri.contains("houtai/xiugaimima")&&!uri.contains("houtai/menu")){
				isPass = false;
				arg1.sendRedirect("/management/houtai/xiugaimima");
			}
			
		}	
		return true;
	}

}
